﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.Master" AutoEventWireup="true" CodeBehind="class.aspx.cs" Inherits="RC1.admin._class" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style1
        {
            width: 115px;
        }
        .style2
        {
            width: 115px;
            height: 30px;
        }
        .style3
        {
            height: 30px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h3>Stovna flokk</h3>
    <table style="width:100%;">
        <tr>
            <td class="style1">
                Flokk heitið</td>
            <td>
                <asp:TextBox ID="classNameTextBox" runat="server" >
                    </asp:TextBox> <span style="color:red;">*</span>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ControlToValidate="classNameTextBox" 
                    ErrorMessage="Flokk skal hava eitt heitið"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style1">
                Lýsing</td>
            <td>
                <asp:TextBox ID="descriptionTextBox" runat="server"></asp:TextBox> <span style="color:red;">*</span>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ControlToValidate="descriptionTextBox" 
                    ErrorMessage="Flokk skal hava eina lýsing"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style1">Lærugrein</td>
            <td>
                <asp:DropDownList ID="subjectDropDownList" runat="server">
                </asp:DropDownList><span style="color:red;">*</span>
            </td>
        </tr>
        <tr>
            <td class="style2">Lærari</td>
            <td class="style3">
                <asp:DropDownList ID="teacherDropDownList" runat="server">
                </asp:DropDownList><span style="color:red;">*</span>
            </td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Stovna" />
            </td>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Angra" />
            </td>
        </tr>
    </table>
    <br />
    <hr />
    <br />
    <h3>Yvirlit</h3>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="class_id" OnRowCommand = "GridviewCommandEventHandler" DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display." CellPadding="5" 
        Width="100%">
        <Columns>
            <asp:BoundField DataField="class_id" HeaderText="class_id" ReadOnly="True" 
                SortExpression="class_id" InsertVisible="False" Visible="False" />
            <asp:BoundField DataField="subject_id" HeaderText="subject_id" 
                SortExpression="subject_id" Visible="False" />
            <asp:ButtonField CommandName="showClass" DataTextField="class_name" 
                HeaderText="Navn" Text="Button" />
            <asp:BoundField DataField="user_id" HeaderText="user_id" 
                SortExpression="user_id" Visible="False" />
            <asp:BoundField DataField="class_description" HeaderText="Lýsing" 
                SortExpression="class_description" />
            <asp:BoundField DataField="user_id1" HeaderText="user_id1" ReadOnly="True" 
                SortExpression="user_id1" Visible="False" />
            <asp:BoundField DataField="user_info_first_name" 
                HeaderText="Fornavn" SortExpression="user_info_first_name" />
            <asp:BoundField DataField="user_info_last_name" 
                HeaderText="Eftirnavn" SortExpression="user_info_last_name" />
            <asp:BoundField DataField="user_info_phone_number" 
                HeaderText="user_info_phone_number" 
                SortExpression="user_info_phone_number" Visible="False" />
            <asp:BoundField DataField="subject_id1" HeaderText="subject_id1" 
                InsertVisible="False" ReadOnly="True" SortExpression="subject_id1" 
                Visible="False" />
            <asp:BoundField DataField="subject_name" HeaderText="Lærugrein" 
                SortExpression="subject_name" />
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <%# getButtons((int)Eval("class_id"))%>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:tsu2011db4ConnectionString1 %>" 
        DeleteCommand="DELETE FROM [class] WHERE [class_id] = @class_id" 
        InsertCommand="INSERT INTO [class] ([subject_id], [user_id], [class_name], [class_description]) VALUES (@subject_id, @user_id, @class_name, @class_description)" 
        ProviderName="<%$ ConnectionStrings:tsu2011db4ConnectionString1.ProviderName %>" 
        SelectCommand="SELECT * FROM [class] JOIN user_info ON class.user_id = user_info.user_id JOIN subject ON class.subject_id = subject.subject_id" 
        
        UpdateCommand="UPDATE [class] SET [subject_id] = @subject_id, [user_id] = @user_id, [class_name] = @class_name, [class_description] = @class_description WHERE [class_id] = @class_id">
        <DeleteParameters>
            <asp:Parameter Name="class_id" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="subject_id" Type="Int32" />
            <asp:Parameter Name="user_id" Type="Int32" />
            <asp:Parameter Name="class_name" Type="String" />
            <asp:Parameter Name="class_description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="subject_id" Type="Int32" />
            <asp:Parameter Name="user_id" Type="Int32" />
            <asp:Parameter Name="class_name" Type="String" />
            <asp:Parameter Name="class_description" Type="String" />
            <asp:Parameter Name="class_id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
